package com.aaa.controller;

import com.aaa.entity.Products;
import com.aaa.entity.Productstype;
import com.aaa.entity.Role;
import com.aaa.entity.Users;
import com.aaa.service.ProductstypeService;
import com.aaa.service.UsersService;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/productstype")
public class ProductstypeController {
    @Autowired
    ProductstypeService productstypeService;

    @RequestMapping("/selectAll")
    public PageInfo<Productstype> selectAll(String typename, Integer currentPage, Integer PageSize){
        PageHelper.startPage(currentPage,PageSize);
        QueryWrapper<Productstype> wrapper=new QueryWrapper<Productstype>();
        wrapper.like("typename",typename);
        List<Productstype> list = productstypeService.list(wrapper);
        PageInfo<Productstype> pageInfo=new PageInfo<Productstype>(list);
        return pageInfo;
    }
    @RequestMapping("/saveOrUpdate")
    public DefaultMsg saveOrUpdate(Productstype productstype){
        DefaultMsg defaultMsg=new DefaultMsg();
        boolean b = productstypeService.saveOrUpdate(productstype);
        if (!b){
            defaultMsg.setCode(500);
            defaultMsg.setSuccess(0);
            defaultMsg.setError("操作失败");
        }
        return defaultMsg;
    }
    @RequestMapping("/delete")
    public DefaultMsg delete(Integer id){
        boolean b = productstypeService.removeById(id);
        DefaultMsg defaultMsg=new DefaultMsg();
        if (!b){
            defaultMsg.setCode(500);
            defaultMsg.setSuccess(0);
            defaultMsg.setError("操作失败");
        }
        return defaultMsg;
    }
}
